package com.link2room.rodimus.controller.manager;

import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.exception.SysException;
import com.link2room.rodimus.facade.IDrawFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.rodimus.dto.param.api.DrawDeliverInfoParamDto;
import com.link2room.rodimus.dto.param.base.DrawPrizeTypeDto;
import com.link2room.rodimus.dto.param.manager.*;
import com.link2room.rodimus.dto.result.base.DrawActivityDto;
import com.link2room.rodimus.dto.result.base.DrawDeliverInfoDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.rodimus.constant.PermissionConstant.*;


/**
 * Created by LN on 2017/7/14.15:00
 */
@Api(tags = "抽奖相关")
@RestController
@RequestMapping("/manager/Draw")
public class DrawManagerController {
    @Resource
    private IDrawFacadeService drawFacadeService;

    @ApiOperation(value = "抽奖活动列表")
    @ApiImplicitParams(value = {
    })
    @RequestMapping(value = "/Activities", method = RequestMethod.GET)
    public BaseResultDto<DrawActivityDto> activitis() throws Exception {
        DrawActivitiesParamDto paramDto = new DrawActivitiesParamDto();
        BaseResultDto resDto = new BaseResultDto();
        resDto.setQueryResult(drawFacadeService.activities(paramDto));
        resDto.setResultCode(0);
        return resDto;

    }

    @ApiOperation(value = "抽奖活动详情")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "activityCode",value = "抽奖活动代码",paramType = "path")
    })
    @RequestMapping(value = "/Activities/{activityCode}", method = RequestMethod.GET)
    public BaseResultDto<DrawActivityDto> activity(@PathVariable("activityCode") String activityCode) throws Exception {
        DrawActivitiesParamDto paramDto = new DrawActivitiesParamDto();
        paramDto.setCode(activityCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo(drawFacadeService.activitiy(paramDto));
        resDto.setResultCode(0);
        return resDto;
    }

    @ApiOperation(value = "抽奖活动修改")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "activityCode",value = "抽奖活动代码",paramType = "path")
    })
    @RequestMapping(value = "/Activities/{activityCode}", method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateDrawActivity, name="更新抽奖活动")
    public BaseResultDto updateActivity(@RequestBody DrawActivitiesUpdateParamDto paramDto, @PathVariable("activityCode") String activityCode) throws Exception {
        paramDto.setCode(activityCode);
        drawFacadeService.updateActivity(paramDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value = "/PrzieBases", method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateDrawPriceBase, name="更新抽奖活动")
    public BaseResultDto updatePrizeBase(@RequestBody DrawPrizeUpdateParamDto paramDto) throws Exception {
        drawFacadeService.updateDrawPrizes(paramDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value = "/PrizeTypes", method = RequestMethod.GET)
    public BaseResultDto<DrawPrizeTypeDto> prizeTypes() throws Exception {

        BaseResultDto resDto = new BaseResultDto();
        resDto.setQueryResult(drawFacadeService.findPrizeBaseType(new BaseL2rParamDto()));
        resDto.setResultCode(0);
        return resDto;
    }
    @Deprecated
    @RequestMapping(value = "/Activities/{activityCode}/jackpot", method = RequestMethod.GET)
    public BaseResultDto getJackpot(@PathVariable("activityCode") String activityCode) throws Exception {
        throw new SysException(BaseSysExceptionEnum.BASE_FUCATION_OPTION,"接口启用.");
       /* DrawJackpotUpdateParamDto paramDto = new DrawJackpotUpdateParamDto();
        paramDto.setActivityCode(activityCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setListToQueryResult(drawFacadeService.getDrawJackDto(paramDto));
        return resDto;*/
    }

    @Deprecated
    @RequestMapping(value = "/Activities/{activityCode}/jackpot", method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateDrawJackpot,name="更新活动奖池")
    public BaseResultDto updateJackpot(
            @PathVariable("activityCode") String activityCode,
            @RequestBody DrawJackpotUpdateParamDto paramDto
    ) throws Exception {
        throw new SysException(BaseSysExceptionEnum.BASE_FUCATION_OPTION,"接口启用.");
      /*  paramDto.setActivityCode(activityCode);
        drawFacadeService.jackpotUpdate(paramDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;*/
    }

    @ApiOperation(value = "发货列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "activityCode",value = "抽奖活动代码",required = true,paramType = "query"),
            @ApiImplicitParam(name = "isDelivered",value = "是否发货",required = false,paramType = "query"),
    })
    @RequestMapping(value = "/deliverInfos", method = RequestMethod.GET)
    public BaseResultDto<DrawDeliverInfoDto> getDeliverInfos(
            @RequestParam(name = "activityCode") String activityCode,
            @RequestParam(name = "isDelivered" , required = false) String isDelivered
            ) throws Exception {
        DrawDeliverInfoParamDto param = new DrawDeliverInfoParamDto();
        param.setActivityCode(activityCode);
        param.setIsDelivered(isDelivered);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setListToQueryResult(drawFacadeService.getDrawDeliverInfoList(param));
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value = "/deliverInfo", method = RequestMethod.GET)
    public BaseResultDto<DrawDeliverInfoDto> getDeliverInfo(
            @RequestParam("prizeNo") String prizeNo) throws Exception {
        DrawDeliverInfoParamDto param = new DrawDeliverInfoParamDto();
        param.setPrizeNo(prizeNo);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo(drawFacadeService.getDeliverInfoByPrizeNo(param));
        resDto.setResultCode(0);
        return resDto;
    }
    @RequestMapping(value = "/deliverInfos/{prizeNo}", method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateDeliverInfos,name="更新奖品发货详情")
    public BaseResultDto updateDeliverInfos(
            @PathVariable("prizeNo") String prizeNo,
            @RequestBody DrawDeliverInfoParamDto param
    ) throws Exception {
        param.setPrizeNo(prizeNo);
        drawFacadeService.updateDrawDeliverInfo(param);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }


    @RequestMapping(value = "/RedoDrawAfter/{activityCode}", method = RequestMethod.POST)
    public BaseResultDto redoDrawAfter(

            @RequestBody DrawAfterDoRedoParamDto param,
            @PathVariable("activityCode") String activityCode) throws Exception {
        param.setActivityCode(activityCode);
        drawFacadeService.redoDrawAfter(param);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

}
